/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cpa_ver_autorizados.java
 *
 * Created on 10/03/2010, 00:23:20
 */

package siga.visao_cpa;

import java.sql.SQLException;
import siga.banco.conexao;
import siga.visao_busca.buscaCpaAvaliacao;
import siga.visao.index;
import siga.visao.verErros;

/**
 *
 * @author rafaelfrasson
 */
public class cpa_ver_autorizados extends javax.swing.JInternalFrame {
    private static String cpa_codigo;
    /** Creates new form cpa_ver_autorizados */
    public cpa_ver_autorizados() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("CPA :: Avaliações Preenchidas");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/cpa_completo.png"))); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/buscar_32x32.png"))); // NOI18N
        jButton3.setText("Avaliação");
        jButton3.setToolTipText("Busca somente Docentes");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Avaliação", "Pessoa", "Situação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(60);
        jTable1.getColumnModel().getColumn(2).setResizable(false);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(80);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 678, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 678, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @SuppressWarnings("static-access")
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        buscaCpaAvaliacao bca = new buscaCpaAvaliacao(null,true);
        bca.setLocation((index.tela.width-bca.getWidth())/2, (index.tela.height-bca.getHeight())/2);
        bca.setVisible(true);
        if(bca.bcpaa_finaliza){
            cpa_codigo = bca.bcpaa_dados.get(0).toString();
            buscarCPA();
        }
}//GEN-LAST:event_jButton3ActionPerformed
    public void buscarCPA(){
        int i = jTable1.getRowCount();
        String txt;
        javax.swing.table.DefaultTableModel jtm = (javax.swing.table.DefaultTableModel)jTable1.getModel();
        for(int x=(i-1);x>=0; --x ){
            jtm.removeRow(x);
        }
        try {
            conexao.Query("select ca.cod_pessoa, ca.cod_resposta, cv.descricao from cpa_autorizados ca " +
                    " inner join cpa_avaliacao cv on cv.codigo=ca.cod_avaliacao and cv.cod_emp=ca.cod_emp " +
                    " where ca.cod_emp="+index.cod_emp+" and ca.cod_avaliacao="+cpa_codigo);
            while (conexao.rs.next()) {
                if(conexao.rs.getString("cod_resposta").toString().equals("0")){txt="Aberto";}else{txt="Preenchido";}
                jtm.addRow(new Object[]{conexao.rs.getString("descricao"),conexao.rs.getString("cod_pessoa"),txt});
            }
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
